<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="变更流水号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入变更流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产编号" prop="instrumentNumber">
        <el-input
          v-model="queryParams.instrumentNumber"
          placeholder="请输入资产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产变更人" prop="changeSituationPerson">
        <el-input
          v-model="queryParams.changeSituationPerson"
          placeholder="请输入资产变更人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产变更日期" prop="changeSituationTm">
        <el-input
          v-model="queryParams.changeSituationTm"
          placeholder="请输入资产变更日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产变更事由" prop="changeSituationResason">
        <el-input
          v-model="queryParams.changeSituationResason"
          placeholder="请输入资产变更事由"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产名称" prop="backupFields1">
        <el-input
          v-model="queryParams.backupFields1"
          placeholder="请输入资产名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="变更类型" prop="backupFields2">
        <el-input
          v-model="queryParams.backupFields2"
          placeholder="请输入变更类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- 
      <el-form-item label="备用字段3" prop="backupFields3">
        <el-input
          v-model="queryParams.backupFields3"
          placeholder="请输入备用字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段4" prop="backupFields4">
        <el-input
          v-model="queryParams.backupFields4"
          placeholder="请输入备用字段4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段5" prop="backupFields5">
        <el-input
          v-model="queryParams.backupFields5"
          placeholder="请输入备用字段5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段6" prop="backupFields6">
        <el-input
          v-model="queryParams.backupFields6"
          placeholder="请输入备用字段6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段7" prop="backupFields7">
        <el-input
          v-model="queryParams.backupFields7"
          placeholder="请输入备用字段7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段8" prop="backupFields8">
        <el-input
          v-model="queryParams.backupFields8"
          placeholder="请输入备用字段8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段9" prop="backupFields9">
        <el-input
          v-model="queryParams.backupFields9"
          placeholder="请输入备用字段9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段10" prop="backupFields10">
        <el-input
          v-model="queryParams.backupFields10"
          placeholder="请输入备用字段10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:change:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:change:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:change:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:change:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="changeList" @selection-change="handleSelectionChange" class="custom-table">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号"  width="55" align="center" prop="id"  />
      <el-table-column label="资产编号" align="center"width="155"  prop="instrumentNumber" />
      <el-table-column label="资产名称" align="center" width="155"prop="backupFields1" />
      <el-table-column label="变更后存放点" align="center" width="155"prop="backupFields4" />
      <el-table-column label="变更后使用人" align="center" width="155"prop="backupFields6">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_code" :value="scope.row.backupFields6" />
        </template>
      </el-table-column>
      <el-table-column label="变更后保管人" align="center"width="155" prop="backupFields5">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_code" :value="scope.row.backupFields5" />
        </template>
      </el-table-column>
      <el-table-column label="变更后责任人" align="center" width="155"prop="backupFields7">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_code" :value="scope.row.backupFields7" />
        </template>
      </el-table-column>
      <el-table-column label="资产变更情况" align="center"width="155" prop="changeSituationStatus" />
      <el-table-column label="资产变更人" align="center" width="155"prop="changeSituationPerson">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_code" :value="scope.row.changeSituationPerson" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="资产变更人" align="center"width="155" prop="changeSituationPerson" /> -->
      <el-table-column label="资产变更时间" align="center"width="155" prop="changeSituationTm" />
      <el-table-column label="资产变更事由" align="center"width="155" prop="changeSituationResason" />
      <el-table-column label="变更时间记录" align="center" width="155"prop="backupFields8" />
      <el-table-column label="变更类型" align="center" width="155"prop="backupFields2" />
       <el-table-column label="变更对象" align="center" width="155"prop="backupFields3" />
      
      <!-- <el-table-column label="变更后保管人" align="center"width="155" prop="backupFields5" />
      <el-table-column label="变更后使用人" align="center" width="155"prop="backupFields6" />
      <el-table-column label="变更后责任人" align="center"width="155" prop="backupFields7" /> -->

      <!-- <el-table-column label="备用字段9" align="center" prop="backupFields9" /> -->
      <!--<el-table-column label="备用字段10" align="center" prop="backupFields10" /> -->
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:change:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:change:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资产变更情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="资产编号" prop="instrumentNumber">
          <el-input v-model="form.instrumentNumber" placeholder="请输入资产编号" />
        </el-form-item>
        <el-form-item label="资产变更人" prop="changeSituationPerson">
          <el-input v-model="form.changeSituationPerson" placeholder="请输入资产变更人" />
        </el-form-item>
        <el-form-item label="资产变更时间" prop="changeSituationTm">
          <el-input v-model="form.changeSituationTm" placeholder="请输入资产变更时间" />
        </el-form-item>
        <el-form-item label="资产变更事由" prop="changeSituationResason">
          <el-input v-model="form.changeSituationResason" placeholder="请输入资产变更事由" />
        </el-form-item>
        <el-form-item label="资产名称" prop="backupFields1">
          <el-input v-model="form.backupFields1" placeholder="请输入备用字段1" />
        </el-form-item>
        <!-- <el-form-item label="备用字段2" prop="backupFields2">
          <el-input v-model="form.backupFields2" placeholder="请输入备用字段2" />
        </el-form-item>
        <el-form-item label="备用字段3" prop="backupFields3">
          <el-input v-model="form.backupFields3" placeholder="请输入备用字段3" />
        </el-form-item>
        <el-form-item label="备用字段4" prop="backupFields4">
          <el-input v-model="form.backupFields4" placeholder="请输入备用字段4" />
        </el-form-item>
        <el-form-item label="备用字段5" prop="backupFields5">
          <el-input v-model="form.backupFields5" placeholder="请输入备用字段5" />
        </el-form-item>
        <el-form-item label="备用字段6" prop="backupFields6">
          <el-input v-model="form.backupFields6" placeholder="请输入备用字段6" />
        </el-form-item>
        <el-form-item label="备用字段7" prop="backupFields7">
          <el-input v-model="form.backupFields7" placeholder="请输入备用字段7" />
        </el-form-item>
        <el-form-item label="备用字段8" prop="backupFields8">
          <el-input v-model="form.backupFields8" placeholder="请输入备用字段8" />
        </el-form-item>
        <el-form-item label="备用字段9" prop="backupFields9">
          <el-input v-model="form.backupFields9" placeholder="请输入备用字段9" />
        </el-form-item>
        <el-form-item label="备用字段10" prop="backupFields10">
          <el-input v-model="form.backupFields10" placeholder="请输入备用字段10" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listChange, getChange, delChange, addChange, updateChange } from "@/api/system/change";

export default {
  name: "Change",
  watch: {
    '$route'(to, from) {
      // 当路由变化时重新加载数据
      if (to.name === 'Change') {
        this.getList();
      }
    }
  },
  dicts: ['user_code'],
  beforeRouteEnter(to, from, next) {
    next(vm => {
      vm.getList(); // 在进入路由前加载数据
    });
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产变更情况表格数据
      changeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        instrumentNumber: null,
        changeSituationStatus: null,
        changeSituationPerson: null,
        changeSituationTm: null,
        changeSituationResason: null,
        backupFields1: null
        // backupFields2: null,
        // backupFields3: null,
        // backupFields4: null,
        // backupFields5: null,
        // backupFields6: null,
        // backupFields7: null,
        // backupFields8: null,
        // backupFields9: null,
        // backupFields10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        instrumentNumber: [
          { required: true, message: "资产编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产变更情况列表 */
    getList() {
      this.loading = true;
      listChange(this.queryParams).then(response => {
        this.changeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        instrumentNumber: null,
        changeSituationStatus: null,
        changeSituationPerson: null,
        changeSituationTm: null,
        changeSituationResason: null,
        backupFields1: null
        // backupFields2: null,
        // backupFields3: null,
        // backupFields4: null,
        // backupFields5: null,
        // backupFields6: null,
        // backupFields7: null,
        // backupFields8: null,
        // backupFields9: null,
        // backupFields10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资产变更情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChange(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改资产变更情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChange(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChange(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产变更情况编号为"' + ids + '"的数据项？').then(function() {
        return delChange(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/change/export', {
        ...this.queryParams
      }, `change_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
/* 自定义表格样式 */
.custom-table {
  /* 设置表格整体滚动条样式 */
  ::-webkit-scrollbar {
    width: 8px;  /* 垂直滚动条宽度 */
    height: 8px; /* 水平滚动条高度 */
  }
  
  /* 滚动条轨道 */
  ::-webkit-scrollbar-track {
    background: #c0bec5;
    border-radius: 4px;
  }
  
  /* 滚动条滑块 */
  ::-webkit-scrollbar-thumb {
    background: #1d77c5;
    border-radius: 4px;
  }
  
  /* 滚动条滑块悬停效果 */
  ::-webkit-scrollbar-thumb:hover {
    background: #942828;
  }
  
  /* 特别针对表格底部滚动条 */
  .el-table__body-wrapper::-webkit-scrollbar {
    height: 15px; /* 调整底部滚动条粗细 */
  }
  
  .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #888;
  }
}
</style>